<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>~/Dokumente/sysi/uebungen/uebung5/sigtest.c.html</title>
<meta name="Generator" content="Vim/7.1">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>



<body bgcolor="#ffffff" text="#000000"><font face="monospace">

pre {
background-color:#F9F9F9;
border:1px dashed #2F6FAB;
color:black;
line-height:1.1em;
padding:1em;
}


<p>
This example below was generated with vim and is within a box you could know from wikipedia.
It looks nice but the ht
</p>

<div style="background-color:#F9F9F9; border:1px dashed #2F6FAB; color:black; padding:1em;">
<font face="monospace">
<font color="#a52a2a">&nbsp;1 </font><font color="#a020f0">#include </font><font color="#ff00ff">&lt;signal.h&gt;</font><br>
<font color="#a52a2a">&nbsp;2 </font><font color="#a020f0">#include </font><font color="#ff00ff">&lt;stdio.h&gt;</font><br>
<font color="#a52a2a">&nbsp;3 </font><font color="#a020f0">#include </font><font color="#ff00ff">&lt;unistd.h&gt;</font><br>
<font color="#a52a2a">&nbsp;4 </font><font color="#a020f0">#include </font><font color="#ff00ff">&lt;string.h&gt;</font><br>
<font color="#a52a2a">&nbsp;5 </font><font color="#a020f0">#include </font><font color="#ff00ff">&lt;errno.h&gt;</font><br>
<font color="#a52a2a">&nbsp;6 </font><font color="#0000ff">/*</font><font color="#0000ff">*</font><br>
<font color="#a52a2a">&nbsp;7 </font><font color="#0000ff">&nbsp;* Excercise 5 task 2</font><br>
<font color="#a52a2a">&nbsp;8 </font><font color="#0000ff">&nbsp;*</font><br>
<font color="#a52a2a">&nbsp;9 </font><font color="#0000ff">&nbsp;* @author&nbsp;&nbsp;Benjamin Friedrich, Ken Dahm</font><br>
<font color="#a52a2a">10 </font><font color="#0000ff">&nbsp;* @version 1.0</font><br>
<font color="#a52a2a">11 </font><font color="#0000ff">&nbsp;* @date&nbsp;&nbsp;&nbsp;&nbsp;01.06.2008</font><br>
<font color="#a52a2a">12 </font><font color="#0000ff">&nbsp;</font><font color="#0000ff">*/</font><br>
<font color="#a52a2a">13 </font><br>
<font color="#a52a2a">14 </font><font color="#2e8b57"><b>volatile</b></font>&nbsp;<font color="#2e8b57"><b>int</b></font>&nbsp;signo = <font color="#ff00ff">0</font>; <font color="#0000ff">//-- global signalNo for the communication between the signal handler and main</font><br>
<font color="#a52a2a">15 </font><br>
<font color="#a52a2a">16 </font><font color="#0000ff">/*</font><font color="#0000ff">*</font><br>
<font color="#a52a2a">17 </font><font color="#0000ff">&nbsp;* Handles the occurence of the initialized signals in (initSignalCalls).</font><br>
<font color="#a52a2a">18 </font><font color="#0000ff">&nbsp;* The handles saves the signal in the global var signo for the communication</font><br>
<font color="#a52a2a">19 </font><font color="#0000ff">&nbsp;* between handler and main </font><br>
<font color="#a52a2a">20 </font><font color="#0000ff">&nbsp;*</font><br>
<font color="#a52a2a">21 </font><font color="#0000ff">&nbsp;* @param&nbsp;&nbsp;signal number</font><br>
<font color="#a52a2a">22 </font><font color="#0000ff">&nbsp;</font><font color="#0000ff">*/</font><br>
<font color="#a52a2a">23 </font><font color="#2e8b57"><b>void</b></font>&nbsp;handler(<font color="#2e8b57"><b>int</b></font>&nbsp;signum)<br>
<font color="#a52a2a">24 </font>{<br>
<font color="#a52a2a">25 </font>&nbsp;&nbsp;&nbsp;&nbsp;signo = signum;<br>
<font color="#a52a2a">26 </font>}<br>
<font color="#a52a2a">27 </font><br>
<font color="#a52a2a">28 </font><br>
<font color="#a52a2a">29 </font><font color="#0000ff">/*</font><font color="#0000ff">*</font><br>
<font color="#a52a2a">30 </font><font color="#0000ff">&nbsp;* Initialize the signal the signal handler for all signal numbers</font><br>
<font color="#a52a2a">31 </font><font color="#0000ff">&nbsp;</font><font color="#0000ff">*/</font><br>
<font color="#a52a2a">32 </font><font color="#2e8b57"><b>int</b></font>&nbsp;initSignalCalls()<br>
<font color="#a52a2a">33 </font>{<br>
<font color="#a52a2a">34 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>int</b></font>&nbsp;i = <font color="#ff00ff">0</font>;<br>
<font color="#a52a2a">35 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>for</b></font>(i = <font color="#ff00ff">SIGHUP</font>; i &lt;= <font color="#ff00ff">SIGUSR2</font>; i++)<br>
<font color="#a52a2a">36 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>
<font color="#a52a2a">37 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#0000ff">//printf(&quot;Signal %d\t-\t%s\n&quot;, i, strsignal(i));</font><br>
<font color="#a52a2a">38 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#a52a2a"><b>if</b></font>(i != <font color="#ff00ff">SIGKILL</font>&nbsp;&amp;&amp; i != <font color="#ff00ff">SIGSTOP</font>) <font color="#0000ff">// signal SIGKILL and SIGSTOP cannot be caught or ignored</font><br>
<font color="#a52a2a">39 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>if</b></font>(signal(i, handler) == <font color="#ff00ff">SIG_ERR</font>)<br>
<font color="#a52a2a">40 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#a52a2a"><b>return</b></font>&nbsp;errno;<br>
<font color="#a52a2a">41 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
<font color="#a52a2a">42 </font><br>
<font color="#a52a2a">43 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>return</b></font>&nbsp;<font color="#ff00ff">0</font>;<br>
<font color="#a52a2a">44 </font>}<br>
<font color="#a52a2a">45 </font><br>
<font color="#a52a2a">46 </font><br>
<font color="#a52a2a">47 </font><font color="#0000ff">/*</font><font color="#0000ff">*</font><br>
<font color="#a52a2a">48 </font><font color="#0000ff">&nbsp;* Main</font><br>
<font color="#a52a2a">49 </font><font color="#0000ff">&nbsp;</font><font color="#0000ff">*/</font><br>
<font color="#a52a2a">50 </font><font color="#2e8b57"><b>int</b></font>&nbsp;main(<font color="#2e8b57"><b>int</b></font>&nbsp;argc, <font color="#2e8b57"><b>char</b></font>&nbsp;**argv)<br>
<font color="#a52a2a">51 </font>{<br>
<font color="#a52a2a">52 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>if</b></font>(initSignalCalls() != <font color="#ff00ff">0</font>)<br>
<font color="#a52a2a">53 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br>
<font color="#a52a2a">54 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;perror(<font color="#ff00ff">&quot;initSignalCall()&quot;</font>);<br>
<font color="#a52a2a">55 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>return</b></font>&nbsp;errno;<br>
<font color="#a52a2a">56 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>
<font color="#a52a2a">57 </font><br>
<font color="#a52a2a">58 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>while</b></font>(sleep(<font color="#ff00ff">60</font>)); <br>
<font color="#a52a2a">59 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
<font color="#a52a2a">60 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>if</b></font>(signo != <font color="#ff00ff">0</font>)<br>
<font color="#a52a2a">61 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(<font color="#ff00ff">&quot;Last received signal: </font><font color="#6a5acd">%d</font><font color="#ff00ff">&nbsp;(</font><font color="#6a5acd">%s</font><font color="#ff00ff">)</font><font color="#6a5acd">\n</font><font color="#ff00ff">&quot;</font>, signo, strsignal(signo));<br>
<font color="#a52a2a">62 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>else</b></font><br>
<font color="#a52a2a">63 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf(<font color="#ff00ff">&quot;No signal received</font><font color="#6a5acd">\n</font><font color="#ff00ff">&quot;</font>);<br>
<font color="#a52a2a">64 </font><br>
<font color="#a52a2a">65 </font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#a52a2a"><b>return</b></font>&nbsp;signo;<br>
<font color="#a52a2a">66 </font>}<br>
</font>
</div>


</body>
</html>